<?php
class Default_Model_ContactTour extends Zend_Db_Table {
	protected $_name    = 'contact_tour';
	
	protected $_primary = 'id';
	

	protected $_referenceMap = array(
			'Tour'=>array(
					'columns' => array('tours_id'),
					'refTableClass' => 'Default_Model_Tour',
					'refColumns' => array('id'),
					'onDelete' => self::CASCADE,
			),
			'Contact'=>array(
					'columns' => array('contact_id'),
					'refTableClass' => 'Default_Model_Contact',
					'refColumns' => array('id'),
					'onDelete' => self::CASCADE,
			)
	
	);
	
	public function saveItem($arrParam = null, $options = null) {
		
		if($options['task'] == 'admin-add') {
			
			$row = $this->fetchNew();
			$row->tours_id   = $arrParam['tours_id'];
			$row->contact_id = $arrParam['contact_id'];
			 	
	        $row->save();
	 
		}
		
		if($options['task'] == 'admin-edit'){
			$id    = $arrParam['id'];
			$where = 'tours_id = ' . $id;
			$row   = $this->fetchRow($where);
			if(empty($row)){
				$row = $this->fetchNew();
				$row->tours_id = $arrParam['id'];
			}
		
			$row->contact_id = $arrParam['contact'];
		
			$row->save();
		
		}
		
	}
	
	// delete item
	public function deleteItem($arrParam = null, $options = null) {
		if($options['task'] == 'admin-delete-tour'){
			$id = $arrParam['id'];
			$where = 'tour_id = ' . $id;
			$this->delete($where);
		}
	}
}